﻿using System;
using System.Collections.Generic;

namespace Raven
{
    public class DisplayObjectFactory
    {
        public delegate DisplayObject DisplayCreator(BaseGameEntity entity);

        static Dictionary<EntityType, DisplayCreator> packageItemExtensions =
            new Dictionary<EntityType, DisplayCreator>();


        public static void SetDisplayCreator(EntityType entityType, Type type)
        {
            packageItemExtensions[entityType] = entity =>
            {
                return (DisplayObject) Activator.CreateInstance(type, entity);
            };
        }

        public static DisplayObject CreateDisplayObject(BaseGameEntity entity)
        {
            EntityType entityType = entity.GetEntityType();
            if (!packageItemExtensions.ContainsKey(entityType))
            {
                return new NoneDisplay(entity);
            }

            return packageItemExtensions[entityType].Invoke(entity);
        }
    }
}